﻿//Write a program that reads two numbers N and K and generates all the variations of K elements from the set [1..N].
//Example: N = 3, K = 2 -> {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}


using System;

public class VariationsOfElements
{
    public static void Main()
    {
        Console.Write("Enter number N = ");
        int numberCount = int.Parse(Console.ReadLine());
        Console.Write("Enter number K = ");
        int variationNumber = int.Parse(Console.ReadLine());
        int[] array = new int[variationNumber];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = 1;
        }
               
        while (array[0] <= numberCount)
        {
            int next = array.Length - 1;
            for (int i = 0; i < numberCount; i++)
            {
                Print(array);
                while (array[next] == numberCount && next > 0)
                {
                    {
                        array[next] = 1;
                        next--;
                    }
                }

                array[next]++;
            }
        }              
    }

    private static void Print(int[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            if (i == 0)
            {
                Console.Write("{{{0}, ", array[i]);
            }
            else if (i == array.Length - 1)
            {
                Console.WriteLine("{0}}}", array[i]);
            }
            else
            {
                Console.Write("{0}, ", array[i]);
            }
        }
    }    
}